import axios from 'axios'
import { defineStore } from 'pinia'
import { Channel } from '../../types/data'
export default defineStore('channel', {
  state: () => {
    // 响应式数据
    return {
      curId: 2,
      list: [] as Channel// 就是一个数组
    }
  },
  actions:{
    setCurId(id: number){
      this.curId = id
    },
    async getChannelList(){
      // res是接口返回的数据
      // axios.get<本接口返回的数据类型>()
      // res.data.本接口返回的数据类型>
      const res = await axios.get<{data:{channels:Channel}, message: string}>('http://geek.itheima.net/v1_0/channels')
      // console.log(res.data.data.channels)
      this.list = res.data.data.channels
    }
  }
})